package psrc.logic.pages.representante;

import java.sql.SQLException;
import java.util.List;

import psrc.bd.dao.RepresentanteDAO;
import psrc.logic.util.beans.RepresentanteBean;

public class RepresentanteModel {

public RepresentanteDAO dao = new RepresentanteDAO(null);
	
	public List<RepresentanteBean> getRepresentantesList() throws Exception{
		return dao.seleciona();
	}
	
	public boolean removeRepresentante (List<RepresentanteBean> representantes) throws Exception{
		try{
			for (RepresentanteBean bean : representantes){
				dao.remove(bean);
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		return true;
	}

	public boolean insert(RepresentanteBean bean) {
		try {
			dao.adiciona(bean);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return true;
		
	}
	
	public boolean update(RepresentanteBean bean) {
		try {
			dao.edita(bean);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return true;
	}
	
	public RepresentanteBean getObjectById(String id){
		RepresentanteBean bean = new RepresentanteBean();
		bean.setIdRepresentante(id);
		try {
			return dao.selecionaPorId(bean).get(0);
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
	}
}
